$(function() {
	var mygrid = $("#list").jqGrid( {
		url : 'admin/department/department!datalist',
		datatype : "json",
		mtype : 'GET',
		colNames : [ '查看', '序号','上级','类型','管理' ],
		colModel : [ {
			name : 'id',
			index : 'id',
			width : 300,
			formatter : viewFormater
		},{
		
			name:"sortNum",
			index:"sortNum"
			
		},{
			
			name:"parent",
			index:"parent",
			width:300,
			formatter:showFormatter
				
		},{
			
			name:"departmentType",
			index:"departmentType",
			width:300,
			formatter:dptTypeFormatter
			
		},{
			name : 'id',
			index : 'id',
			width : 30,
			formatter : removeFormatter
		}],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'name',
		sortorder : 'desc',
		viewrecords : true,
		caption : '部门列表',
		width : '700',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	})
	.jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	})
	.jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			doGet('admin/department/input?action=add');
		},
		buttonicon : "ui-icon-newwin",
		caption : "添加"
	})
	.jqGrid("navButtonAdd", "#pager", {
		onClickButton : function() {
			doGet('admin/department/startsort');
		},
		buttonicon : "ui-icon-newwin",
		caption : "排序"
	});

	
});
function showFormatter(v,opt,row){
	return v?v.name:"-";
}
function viewFormater(val, opt, row) {

	var url = "admin/department/department!get?bean.id="+val;	
var a = $("<a></a>").attr("onclick","doGet('"+url+"')").attr("href","javascript:void(0);").html(row['name']);
	
	return a.get(0).outerHTML;
	

}
function dptTypeFormatter(v,opt,row){
	return v==undefined?'未定义':v;
}

function removeFormatter(val, opt, row) {
	var url = 'admin/department/department!remove?bean.id=' + val;
	var a = $("<a>删除</a>").attr("onclick","doSubmit('"+url+"',' ',true)").attr("href","javascript:void(0);");
	return a.get(0).outerHTML;
}	